package nuonuo.com.view.customview;

import android.content.Context;
import android.view.View;
import android.widget.Scroller;

/**
 * Created by n6 on 2017/2/28.
 */

public class ScrollerView extends View {

    private Scroller mScroller;

    public ScrollerView(Context context) {
        super(context);
        mScroller = new Scroller(context);
    }

    private void smoothScrollTo(int destX,int destY){
        int scrollX = getScrollX();
        int scrollY = getScrollY();
        int deltaX = destX - scrollX;
        int deltaY = destY - scrollY;
        mScroller.startScroll(scrollX,scrollY,deltaX,deltaY);
    }

    @Override
    public void computeScroll() {
        if (mScroller.computeScrollOffset()){
            scrollTo(mScroller.getCurrX(),mScroller.getCurrY());
            postInvalidate();
        }
    }
}
